



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class CountryDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public CountryDB()
        {
        }

        public CountryDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Country> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Country> lstRet = new List<Country>();

            string strQuery = " select " + strTop  + " * from dbo.[Country]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Country obj = new Country();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["CountryNameAR"] != DBNull.Value)
                    {
                        obj.CountryNameAR = (System.String)dr["CountryNameAR"];
                    }
                    else
                    {
                        obj.CountryNameAR = "";
                    } 
 if (dr["CountryNameEN"] != DBNull.Value)
                    {
                        obj.CountryNameEN = (System.String)dr["CountryNameEN"];
                    }
                    else
                    {
                        obj.CountryNameEN = "";
                    } 
 if (dr["CountryCodeEN"] != DBNull.Value)
                    {
                        obj.CountryCodeEN = (System.String)dr["CountryCodeEN"];
                    }
                    else
                    {
                        obj.CountryCodeEN = "";
                    } 
 if (dr["CountryCode"] != DBNull.Value)
                    {
                        obj.CountryCode = (System.String)dr["CountryCode"];
                    }
                    else
                    {
                        obj.CountryCode = "";
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Country> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Country> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Country obj)
        {
            
            

                    DbParameter prmCountryNameAR = con.createParameter();
                    prmCountryNameAR.ParameterName = "@CountryNameAR";
                    prmCountryNameAR.DbType =DbType.String;
                    if (obj.CountryNameAR == null)
                    {
                        prmCountryNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryNameAR.Value = obj.CountryNameAR;
                    }
                

                    


                    DbParameter prmCountryNameEN = con.createParameter();
                    prmCountryNameEN.ParameterName = "@CountryNameEN";
                    prmCountryNameEN.DbType =DbType.String;
                    if (obj.CountryNameEN == null)
                    {
                        prmCountryNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryNameEN.Value = obj.CountryNameEN;
                    }
                

                    


                    DbParameter prmCountryCodeEN = con.createParameter();
                    prmCountryCodeEN.ParameterName = "@CountryCodeEN";
                    prmCountryCodeEN.DbType =DbType.String;
                    if (obj.CountryCodeEN == null)
                    {
                        prmCountryCodeEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryCodeEN.Value = obj.CountryCodeEN;
                    }
                

                    


                    DbParameter prmCountryCode = con.createParameter();
                    prmCountryCode.ParameterName = "@CountryCode";
                    prmCountryCode.DbType =DbType.String;
                    if (obj.CountryCode == null)
                    {
                        prmCountryCode.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryCode.Value = obj.CountryCode;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Country] ([CountryNameAR],[CountryNameEN],[CountryCodeEN],[CountryCode]) VALUES (@CountryNameAR,@CountryNameEN,@CountryCodeEN,@CountryCode) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmCountryNameAR,prmCountryNameEN,prmCountryCodeEN,prmCountryCode);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Country obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Country obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmCountryNameAR = con.createParameter();
                    prmCountryNameAR.ParameterName = "@CountryNameAR";
                    prmCountryNameAR.DbType =DbType.String;
                    if (obj.CountryNameAR == null)
                    {
                        prmCountryNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryNameAR.Value = obj.CountryNameAR;
                    }
                

                    


                    DbParameter prmCountryNameEN = con.createParameter();
                    prmCountryNameEN.ParameterName = "@CountryNameEN";
                    prmCountryNameEN.DbType =DbType.String;
                    if (obj.CountryNameEN == null)
                    {
                        prmCountryNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryNameEN.Value = obj.CountryNameEN;
                    }
                

                    


                    DbParameter prmCountryCodeEN = con.createParameter();
                    prmCountryCodeEN.ParameterName = "@CountryCodeEN";
                    prmCountryCodeEN.DbType =DbType.String;
                    if (obj.CountryCodeEN == null)
                    {
                        prmCountryCodeEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryCodeEN.Value = obj.CountryCodeEN;
                    }
                

                    


                    DbParameter prmCountryCode = con.createParameter();
                    prmCountryCode.ParameterName = "@CountryCode";
                    prmCountryCode.DbType =DbType.String;
                    if (obj.CountryCode == null)
                    {
                        prmCountryCode.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCountryCode.Value = obj.CountryCode;
                    }
                

                    


           



            string strQuery = " update dbo.[Country] set [CountryNameAR]=@CountryNameAR,[CountryNameEN]=@CountryNameEN,[CountryCodeEN]=@CountryCodeEN,[CountryCode]=@CountryCode where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmCountryNameAR,prmCountryNameEN,prmCountryCodeEN,prmCountryCode);

            

        }


        public void Update(Country obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Country obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Country]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Country obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Country> getCountryByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Country> lstRet = new List<Country>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Country> getCountryByID(System.Int64 ID)
                    {
                        List<Country> lstRet = new List<Country>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCountryByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Country> getCountryByCountryNameAR(ClassDataHandler con,System.String CountryNameAR)
                    {
                        List<Country> lstRet = new List<Country>();


                        DbParameter prmCountryNameAR = con.createParameter();
                        prmCountryNameAR.ParameterName = "@CountryNameAR";
                        prmCountryNameAR.DbType = DbType.String;
                        if (CountryNameAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCountryNameAR.Value = CountryNameAR;
                        }


                        lstRet = Select(con, "" , " where [CountryNameAR]=@CountryNameAR ", prmCountryNameAR);



                        return lstRet;

                    }


                    public List<Country> getCountryByCountryNameAR(System.String CountryNameAR)
                    {
                        List<Country> lstRet = new List<Country>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCountryByCountryNameAR(con, CountryNameAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Country> getCountryByCountryNameEN(ClassDataHandler con,System.String CountryNameEN)
                    {
                        List<Country> lstRet = new List<Country>();


                        DbParameter prmCountryNameEN = con.createParameter();
                        prmCountryNameEN.ParameterName = "@CountryNameEN";
                        prmCountryNameEN.DbType = DbType.String;
                        if (CountryNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCountryNameEN.Value = CountryNameEN;
                        }


                        lstRet = Select(con, "" , " where [CountryNameEN]=@CountryNameEN ", prmCountryNameEN);



                        return lstRet;

                    }


                    public List<Country> getCountryByCountryNameEN(System.String CountryNameEN)
                    {
                        List<Country> lstRet = new List<Country>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCountryByCountryNameEN(con, CountryNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Country> getCountryByCountryCodeEN(ClassDataHandler con,System.String CountryCodeEN)
                    {
                        List<Country> lstRet = new List<Country>();


                        DbParameter prmCountryCodeEN = con.createParameter();
                        prmCountryCodeEN.ParameterName = "@CountryCodeEN";
                        prmCountryCodeEN.DbType = DbType.String;
                        if (CountryCodeEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCountryCodeEN.Value = CountryCodeEN;
                        }


                        lstRet = Select(con, "" , " where [CountryCodeEN]=@CountryCodeEN ", prmCountryCodeEN);



                        return lstRet;

                    }


                    public List<Country> getCountryByCountryCodeEN(System.String CountryCodeEN)
                    {
                        List<Country> lstRet = new List<Country>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCountryByCountryCodeEN(con, CountryCodeEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Country> getCountryByCountryCode(ClassDataHandler con,System.String CountryCode)
                    {
                        List<Country> lstRet = new List<Country>();


                        DbParameter prmCountryCode = con.createParameter();
                        prmCountryCode.ParameterName = "@CountryCode";
                        prmCountryCode.DbType = DbType.String;
                        if (CountryCode == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCountryCode.Value = CountryCode;
                        }


                        lstRet = Select(con, "" , " where [CountryCode]=@CountryCode ", prmCountryCode);



                        return lstRet;

                    }


                    public List<Country> getCountryByCountryCode(System.String CountryCode)
                    {
                        List<Country> lstRet = new List<Country>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCountryByCountryCode(con, CountryCode);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Country> Search(ClassDataHandler con, Country obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.CountryNameAR != "")
                    {
                        DbParameter prmCountryNameAR = con.createParameter();
                        prmCountryNameAR.ParameterName = "@CountryNameAR";
                        prmCountryNameAR.DbType =DbType.String;
                        if (obj.CountryNameAR == null)
                        {
                            prmCountryNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryNameAR.Value = obj.CountryNameAR;
                        }
                        strWhere += " [CountryNameAR]=@CountryNameAR AND ";
                        lstParameters.Add(prmCountryNameAR);
                     }



                    

                    if (obj.CountryNameEN != "")
                    {
                        DbParameter prmCountryNameEN = con.createParameter();
                        prmCountryNameEN.ParameterName = "@CountryNameEN";
                        prmCountryNameEN.DbType =DbType.String;
                        if (obj.CountryNameEN == null)
                        {
                            prmCountryNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryNameEN.Value = obj.CountryNameEN;
                        }
                        strWhere += " [CountryNameEN]=@CountryNameEN AND ";
                        lstParameters.Add(prmCountryNameEN);
                     }



                    

                    if (obj.CountryCodeEN != "")
                    {
                        DbParameter prmCountryCodeEN = con.createParameter();
                        prmCountryCodeEN.ParameterName = "@CountryCodeEN";
                        prmCountryCodeEN.DbType =DbType.String;
                        if (obj.CountryCodeEN == null)
                        {
                            prmCountryCodeEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryCodeEN.Value = obj.CountryCodeEN;
                        }
                        strWhere += " [CountryCodeEN]=@CountryCodeEN AND ";
                        lstParameters.Add(prmCountryCodeEN);
                     }



                    

                    if (obj.CountryCode != "")
                    {
                        DbParameter prmCountryCode = con.createParameter();
                        prmCountryCode.ParameterName = "@CountryCode";
                        prmCountryCode.DbType =DbType.String;
                        if (obj.CountryCode == null)
                        {
                            prmCountryCode.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryCode.Value = obj.CountryCode;
                        }
                        strWhere += " [CountryCode]=@CountryCode AND ";
                        lstParameters.Add(prmCountryCode);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Country> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Country> Search(Country obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Country> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Country> SearchOrLike(ClassDataHandler con, Country obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.CountryNameAR != "")
                    {
                        DbParameter prmCountryNameAR = con.createParameter();
                        prmCountryNameAR.ParameterName = "@CountryNameAR";
                        prmCountryNameAR.DbType =DbType.String;
                        if (obj.CountryNameAR == null)
                        {
                            prmCountryNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryNameAR.Value = obj.CountryNameAR;
                        }
                        strWhere += " [CountryNameAR] LIKE @CountryNameAR OR ";
                        lstParameters.Add(prmCountryNameAR);
                     }



                    

                    if (obj.CountryNameEN != "")
                    {
                        DbParameter prmCountryNameEN = con.createParameter();
                        prmCountryNameEN.ParameterName = "@CountryNameEN";
                        prmCountryNameEN.DbType =DbType.String;
                        if (obj.CountryNameEN == null)
                        {
                            prmCountryNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryNameEN.Value = obj.CountryNameEN;
                        }
                        strWhere += " [CountryNameEN] LIKE @CountryNameEN OR ";
                        lstParameters.Add(prmCountryNameEN);
                     }



                    

                    if (obj.CountryCodeEN != "")
                    {
                        DbParameter prmCountryCodeEN = con.createParameter();
                        prmCountryCodeEN.ParameterName = "@CountryCodeEN";
                        prmCountryCodeEN.DbType =DbType.String;
                        if (obj.CountryCodeEN == null)
                        {
                            prmCountryCodeEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryCodeEN.Value = obj.CountryCodeEN;
                        }
                        strWhere += " [CountryCodeEN] LIKE @CountryCodeEN OR ";
                        lstParameters.Add(prmCountryCodeEN);
                     }



                    

                    if (obj.CountryCode != "")
                    {
                        DbParameter prmCountryCode = con.createParameter();
                        prmCountryCode.ParameterName = "@CountryCode";
                        prmCountryCode.DbType =DbType.String;
                        if (obj.CountryCode == null)
                        {
                            prmCountryCode.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCountryCode.Value = obj.CountryCode;
                        }
                        strWhere += " [CountryCode] LIKE @CountryCode OR ";
                        lstParameters.Add(prmCountryCode);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Country> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Country> SearchOrLike(Country obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Country> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            